package cn.oms.auth.service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.client.RestTemplate;

/** 基于SSM的门诊管理系统 曾晨AllenChen版权所有@1.0.0 **/

@SpringBootApplication
// 用于让nacos发现 将服务注册到nacos注册中心
@EnableDiscoveryClient
public class OmsAuthServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(OmsAuthServiceApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public FilterRegistrationBean registrationBean(){
        FilterRegistrationBean<CorsFilter> bean=
                new FilterRegistrationBean<>();
        // 设置哪些路径要经过滤器的处理
        bean.addUrlPatterns("/*");// 所有路径都需要过滤
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);// 设置优先级最高
        bean.setFilter(new CorsFilter());// 设置过滤器对象
        return bean;//返回设置到Spring容器
    }
}
